#ifndef VDataModel_H
#define VDataModel_H

#include "VTreeNode.h"
#include "VTreeSql.h"

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

class VDataModel : public QAbstractItemModel
{
	Q_OBJECT

public:
	VDataModel(QObject *parent = 0);
	~VDataModel();

	void setNode(VTreeNode *node);
	VDataTable *dataTable() const { return m_dataTable;}

	QModelIndex index(int row, int column,const QModelIndex &parent = QModelIndex()) const;
	QModelIndex parent(const QModelIndex &index) const;

	QVariant headerData(int section, Qt::Orientation orientation,int role = Qt::DisplayRole) const;

	int rowCount(const QModelIndex &parent = QModelIndex()) const;
	int columnCount(const QModelIndex &parent = QModelIndex()) const;

	Qt::ItemFlags flags(const QModelIndex &index) const;

	QVariant data(const QModelIndex &index, int role) const;
	bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);

	bool insertRows(int position, int rows,	const QModelIndex &parentIndex = QModelIndex());
	bool removeRows(int position, int rows,	const QModelIndex &parentIndex = QModelIndex());

	bool hasChildren (const QModelIndex &parent = QModelIndex()) const;
	bool canFetchMore(const QModelIndex &parent) const;
	void fetchMore   (const QModelIndex &parent);

	VDataField *dataFieldFromIndex(const QModelIndex &index) const;

private:
	VDataTable *m_dataTable;
};

///////////////////////////////////////////////////////////////////////////////

#endif
